package com.tfb.boot.controller;

import com.tfb.boot.bean.Person;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
public class HelloController {

    @ResponseBody
    @GetMapping("/hello")
    public String hello(){
        int i=1/0;
        return "hello world";
    }
    @GetMapping("/dog")
    public Map<String,Object> dog(@RequestParam(value = "name",required = false)String name){
        HashMap<String, Object> map = new HashMap<>();
        map.put("name",name);
        return map;
    }

    @GetMapping("/dog/{age}")
    public String dogAge(@RequestParam("name")String name,
                                     @PathVariable("age") int age,
                                     Model model){

        model.addAttribute("name",name);
        model.addAttribute("age",age);
        return "redirect:/hello";
    }

    @ResponseBody
    @PostMapping("/person")
    public Person addPerson(Person person){
        return person;

    }

    @ResponseBody
    @GetMapping("/getperson")
    public Person getPerson(){
        return new Person();
    }

    @GetMapping("/topage")
    public String toPage(){
        return "getperson";
    }
}
